#!/usr/bin/python
# -*- coding: UTF-8 -*-
from itertools import islice

def format_num(n):
    if n<10:
        return "0"+str(n)
    return str(n)

fn="D:/byd_shell/Report_20190413"
rp="[DEBUG](SMDDatabase::NotifyReportStatus) USP_SMG_UpdateMessageReportStatus"
with open(fn, "r", encoding='gbk') as f:
    count=0
    fileIndex = 1
    wf=open(fn+"_"+format_num(fileIndex)+".sql", "w", encoding='gbk')
    while 1:
        size=1024*1024#一次读取1M
        lines =f.readlines(size)
        if not lines:
            break
        # for line in lines:
        #     print(line,)

        print(len(lines))

        for line in lines:
            # line=line.strip()
            line=line.replace(rp,"exec")
            count=count+1
            wf.write(line)
            if(count>=100000):
                count=0
                fileIndex=fileIndex+1
                wf.close()
                wf = open(fn+"_" + format_num(fileIndex)+".sql", "w", encoding='gbk')

           # print(line.strip())

    if not wf.closed:
        wf.close()